package 二叉搜索树中的搜索;

/**
 * @author zhengTao
 * @version 1.0
 * @description: 二叉搜索树中的搜索
 * @date 2022/11/6 14:32
 */
public class Demo700 {
    public TreeNode searchBST(TreeNode root, int val) {
        if(root==null){
            return null;
        }
        if(root.val<val){
            root=root.right;
            return searchBST(root,val);
        } else if(root.val>val){
            root=root.left;
            return searchBST(root,val);
        }else {
            return root;
        }
    }
    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode() {}
        TreeNode(int val) {
            this.val = val;}
        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }
}
